package com.baizhi.controller;

import com.baizhi.entity.Category;
import com.baizhi.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    @RequestMapping("addCategory")
    @ResponseBody
    public Map addCategory(Category category){
        Map map = new HashMap();
        categoryService.insertCategory(category);
        map.put("flag",true);
        return map;
    }
    @RequestMapping("removeCategory")
    @ResponseBody
    public Map removeCategory(Integer id){
        System.out.println("remove parm:"+id);
        Map map = new HashMap();
        categoryService.deleteCategory(id);
        map.put("flag",true);
        return map;
    }
    @RequestMapping("selectAllCategory")
    @ResponseBody
    public Map selectAllCategory(){
        Map map = new HashMap();
        List<Category> categories = categoryService.selectAll();
        map.put("code",0);
        map.put("msg","");
//        map.put("count",pageInfo.getTotal());
        map.put("data",categories);
        return map;
    }
    @RequestMapping("selectFirstCategory")
    @ResponseBody
    public Map selectFirstCategory(){
        Map map = new HashMap();
        List<Category> categories = categoryService.selectFirstCategory();
//        map.put("code",0);
//        map.put("msg","");
        map.put("list",categories);
        return map;
    }
    @RequestMapping("selectSecondCategory")
    @ResponseBody
    public Map selectSecondCategory(){
        Map map = new HashMap();
        List<Category> categories = categoryService.selectSecondCategory();
//        map.put("code",0);
//        map.put("msg","");
        map.put("list",categories);
        return map;
    }
}
